package com.example.liwushuo;

import java.util.ArrayList;
import java.util.List;

import com.example.liwushuo.adapter.SearchAdapter;
import com.example.liwushuo.fragment.SearchGifFragment;
import com.viewpagerindicator.TabPageIndicator;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.app.Activity;

public class SearchActivity extends ActionBarActivity implements
		OnClickListener {

	private TextView search;
	private EditText edittext;
	private ImageView fanhui;
	private TabPageIndicator tab;
	private ViewPager viewPager;
	private List<Fragment> list;
	private SearchAdapter adapter;
	private LinearLayout layout;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_search);

		initView();

		fanhui.setOnClickListener(this);
		search.setOnClickListener(this);

	}

	private void initView() {
		fanhui = (ImageView) findViewById(R.id.search_fanhui);
		search = (TextView) findViewById(R.id.search_tv);
		edittext = (EditText) findViewById(R.id.search_edittext);
		viewPager = (ViewPager) findViewById(R.id.search_viewPager);
		tab = (TabPageIndicator) findViewById(R.id.search_tab);
		list = new ArrayList<Fragment>();
		adapter = new SearchAdapter(getSupportFragmentManager());
		viewPager.setAdapter(adapter);
		tab.setViewPager(viewPager);
		layout = (LinearLayout) findViewById(R.id.search_layout_id);
		layout.setVisibility(View.GONE);
	}

	@Override
	public void onClick(View v) {

		switch (v.getId()) {
		case R.id.search_fanhui:
			Toast.makeText(this, "fanhui", 1).show();
			break;
		case R.id.search_tv:
			// 获取输入框中的数据
			String key = edittext.getText().toString();
			Bundle args = new Bundle();
			args.putString("key", key);
			SearchGifFragment search = new SearchGifFragment();
			search.setArguments(args);
			SearchGifFragment search2 = new SearchGifFragment();
			search.setArguments(args);
			list.add(search);
			list.add(search2);
			adapter.notifyDataSetChanged();
			layout.setVisibility(View.VISIBLE);
			break;
		}
	}
}
